package com.hawk.eye.framework.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

/**
 * @author salad
 */
public class RegexUtil {


    public static Pattern compile(String target) {
        try {
            return Pattern.compile(target);
        } catch (PatternSyntaxException e) {
            return null;
        }
    }

    public static boolean matcher(String str, String regex) {
        Pattern compile = compile(regex);
        if (compile == null) {
            throw new RuntimeException("[" + regex + "]不是合法的正则表达式");
        }
        Matcher matcher = compile.matcher(str);
        return matcher.matches();
    }

    public static boolean matcher(String str, Pattern compile) {
        Matcher matcher = compile.matcher(str);
        return matcher.matches();
    }

}